package com.idione.activities;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.idione.controller.ContraReloj;
import com.idione.controller.ObtenTuLicencia;
import com.idione.controller.PracticaUnPoco;
import com.idione.util.LogUtil;
import com.idione.util.SoundSingleton;

public class Play extends Activity implements OnClickListener {

	private Toast toast;
	private Intent intent;
	
	private Button btnJuego1;	
	private Button btnJuego2;
	private Button btnJuego3;
	private Button btnJuegoHelp1;
	private Button btnJuegoHelp2;
	private Button btnJuegoHelp3;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.log("onCreate(Bundle)");

		setContentView(R.layout.play);

		/* -----------------------------------------------------------------*
		 * set Listener														*
		 *------------------------------------------------------------------*/
		btnJuego1 = (Button) findViewById(R.id.BtnJuego1);
		btnJuego2 = (Button) findViewById(R.id.BtnJuego2);
		btnJuego3 = (Button) findViewById(R.id.BtnJuego3);

		btnJuegoHelp1 = (Button) findViewById(R.id.BtnGameHelp1);
		btnJuegoHelp2 = (Button) findViewById(R.id.BtnGameHelp2);
		btnJuegoHelp3 = (Button) findViewById(R.id.BtnGameHelp3);

		btnJuego1.setOnClickListener(this);
		btnJuego2.setOnClickListener(this);
		btnJuego3.setOnClickListener(this);	
		btnJuegoHelp1.setOnClickListener(this);
		btnJuegoHelp2.setOnClickListener(this);
		btnJuegoHelp3.setOnClickListener(this);	
		
		this.setTypeFace();
	}

	private void setTypeFace() {
		Typeface tf = LogUtil.getTypeFaceButton(this);
		
		btnJuego1.setTypeface(tf);
		btnJuego2.setTypeface(tf);
		btnJuego3.setTypeface(tf);
		btnJuegoHelp1.setTypeface(tf);
		btnJuegoHelp2.setTypeface(tf);
		btnJuegoHelp3.setTypeface(tf);
	}
	
	@Override
	public synchronized void onClick(View call) {
		this.log("onClick(View)");

		SoundSingleton.getInstance().PlaySoundClick();
		switch (call.getId()) {
		case R.id.BtnJuego1:
			intent = new Intent(this, QuestionContraReloj.class);
			intent.putExtra("Game", new ContraReloj(this));
			startActivity(intent);
			overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
			break;
		case R.id.BtnJuego2:
			intent = new Intent(this, QuestionObtenTuLicencia.class);
			intent.putExtra("Game", new ObtenTuLicencia(this));
			startActivity(intent);
			overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
			break;
		case R.id.BtnJuego3:
			intent = new Intent(this, QuestionPracticaUnPoco.class);
			intent.putExtra("Game", new PracticaUnPoco(this));
			startActivity(intent);
			overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);
			break;
		case R.id.BtnGameHelp1:
			toast = Toast.makeText(this, R.string.Game1Hint, Toast.LENGTH_LONG*2);
			toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL, 0, 0);
			toast.show();
			break;
		case R.id.BtnGameHelp2:
			toast = Toast.makeText(this, R.string.Game2Hint, Toast.LENGTH_LONG*2);
			toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL, 0, 0);
			toast.show();
			break;
		case R.id.BtnGameHelp3:
			toast = Toast.makeText(this, R.string.Game3Hint, Toast.LENGTH_LONG*2);
			toast.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL, 0, 0);
			toast.show();
			break;
		}
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
		overridePendingTransition(R.anim.push_rigth_in, R.anim.push_rigth_out);
	}

	/*--------------------------------------------------------------------------*
	 * Log																		*
	 *--------------------------------------------------------------------------*/
	private final String LOGTAG = "LogsClass " + this.getClass().getName();
	private void log(String method) {
		if (LogUtil.activitiesLog)
			Log.i(LOGTAG, "... method : " + this.getClass().getSimpleName() + "." + method);
	}
}
